<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>单页管理编辑--${site.name}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="${site.description}"/>
    <meta name="keywords" content="${site.keywords}"/>
    <meta name="author" content="${site.author}"/>
    <link rel="icon" href="${site.logo}">
    <link rel="stylesheet" href="${base}/static/layui/css/layui.css" media="all" />
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
        .layui-form-item .role-box {
            position: relative;
        }
        .layui-form-item .role-box .jq-role-inline {
            height: 100%;
            overflow: auto;
        }

    </style>
</head>
<body class="childrenBody">



<form class="layui-form" style="width:80%;">
    <input value="${electricitySinglepage.id}" name="id" type="hidden">
    <div class="layui-form-item" style="position: relative;z-index:999">
        <label class="layui-form-label">显示类型</label>
        <div class="layui-input-block">
            <select id="showType" lay-filter="showType" onchange="typeChange()">
                <option value="1" selected>PC端</option>
                <option value="2" >手机端</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item showPc" style="position: relative;z-index: 998">
        <label class="layui-form-label">PC端内容</label>
        <div class="layui-input-block">
            <div id="content">${electricitySinglepage.content}</div>

        </div>
    </div>
    <div class="layui-form-item showPhone" style="display: none;position: relative;z-index: 998">
        <label class="layui-form-label">手机端内容</label>
        <div class="layui-input-block">
            <div id="phoneContent">${electricitySinglepage.phoneContent}</div>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type" >
                <option value="" selected="">请选择类型</option>
                <@my type="electricity_singlepage_type">
                    <#list result as r>
                        <option value="${r.value}"  <#if (electricitySinglepage.type == r.value)> selected="" </#if>  >${r.label}</option>
                    </#list>
                </@my>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <#assign electricity_singlepage_status_yes="">
            <#assign electricity_singlepage_status_yes_value="">
            <#assign electricity_singlepage_status_no="">
            <@my type="electricity_singlepage_status">
                <#list result as r>
                    <#if (r_index == 0)>
                        <#assign electricity_singlepage_status_yes="${r.label}">
                        <#assign electricity_singlepage_status_yes_value="${r.value}">
                    </#if>
                    <#if (r_index == 1)>
                        <#assign electricity_singlepage_status_no="${r.label}">
                    </#if>
                </#list>
            </@my>
            <input type="checkbox" name="status"  lay-skin="switch" lay-text="${electricity_singlepage_status_yes}|${electricity_singlepage_status_no}" <#if (electricitySinglepage.status == electricity_singlepage_status_yes_value)> checked </#if>>

        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addElectricitySinglepage">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="${base}/static/layui/layui.js"></script>
<script type="text/javascript" src="${base}/static/js/wangEditor.min.js"></script>
<script type="text/javascript" src="${base}/static/js/libs/jquery-2.1.1.min.js"></script>
<script>
    layui.use(['form','jquery','layer','upload'],function(){
        var form      = layui.form,
            $     = layui.jquery,
            upload = layui.upload,
            laydate = layui.laydate,
            E = window.wangEditor,
            layer = layui.layer;

        form.on('select(showType)', function(data){
            var value = data.value;
            if(value==1){
                $(".showPc").show();
                $(".showPhone").hide();
            }else {
                $(".showPc").hide();
                $(".showPhone").show();
            }
        });

        var content_editor = new E('#content');
        //图片上传
        content_editor.customConfig.uploadImgServer = '${base}/file/uploadWang';
        content_editor.customConfig.uploadFileName = 'test';
        // 自定义处理粘贴的文本内容(这里处理图片抓取)
        content_editor.customConfig.pasteTextHandle = function (content) {
            if(undefined == content){
                return content;
            }
            if(content.indexOf("src=")<=0){
                return content;
            }
            var loadContent = layer.load(2, {
                shade: [0.3, '#333']
            });
            $.ajax({
                url: "${base}/file/doContent/",
                type: "POST",
                async: false,
                data:{"content":content},
                dataType: "json",
                success:function(res){
                    layer.close(loadContent);
                    content = res.data;
                }
            });
            return content;
        };
        // 关闭粘贴样式的过滤
        content_editor.customConfig.pasteFilterStyle = false;
        content_editor.customConfig.customAlert = function (info) {
            // info 是需要提示的内容
            layer.msg(info);
        };
        content_editor.create();
        var phoneContent_editor = new E('#phoneContent');
        //图片上传
        phoneContent_editor.customConfig.uploadImgServer = '${base}/file/uploadWang';
        phoneContent_editor.customConfig.uploadFileName = 'test';
        // 自定义处理粘贴的文本内容(这里处理图片抓取)
        phoneContent_editor.customConfig.pasteTextHandle = function (content) {
            if(undefined == content){
                return content;
            }
            if(content.indexOf("src=")<=0){
                return content;
            }
            var loadContent = layer.load(2, {
                shade: [0.3, '#333']
            });
            $.ajax({
                url: "${base}/file/doContent/",
                type: "POST",
                async: false,
                data:{"content":content},
                dataType: "json",
                success:function(res){
                    layer.close(loadContent);
                    content = res.data;
                }
            });
            return content;
        };
        // 关闭粘贴样式的过滤
        phoneContent_editor.customConfig.pasteFilterStyle = false;
        phoneContent_editor.customConfig.customAlert = function (info) {
            // info 是需要提示的内容
            layer.msg(info);
        };
        phoneContent_editor.create();

        form.on("submit(addElectricitySinglepage)",function(data){
            var c = content_editor.txt.html();
            c = c.replace(/\"/g, "'");
            data.field.content = c;
            <#assign electricity_singlepage_status_yes="">
            <#assign electricity_singlepage_status_yes_value="">
            <#assign electricity_singlepage_status_no="">
            <#assign electricity_singlepage_status_no_value="">
            <@my type="electricity_singlepage_status">
            <#list result as r>
            <#if (r_index == 0)>
            <#assign electricity_singlepage_status_yes="${r.label}">
            <#assign electricity_singlepage_status_yes_value="${r.value}">
            </#if>
            <#if (r_index == 1)>
            <#assign electricity_singlepage_status_no="${r.label}">
            <#assign electricity_singlepage_status_no_value="${r.value}">
            </#if>
            </#list>
            </@my>
            if(undefined === data.field.status || '${electricity_singlepage_status_no_value}' === data.field.status || null === data.field.status){
                data.field.status = ${electricity_singlepage_status_no_value};
            }else{
                data.field.status = ${electricity_singlepage_status_yes_value};
            }
            var c = phoneContent_editor.txt.html();
            c = c.replace(/\"/g, "'");
            data.field.phoneContent = c;
            var loadIndex = layer.load(2, {
                shade: [0.3, '#333']
            });
            //给角色赋值
            $.post("${base}/admin/electricitySinglepage/edit",data.field,function(res){
                layer.close(loadIndex);
                if(res.success){
                    parent.layer.msg("单页管理编辑成功！",{time:1000},function(){
                        parent.layer.close(parent.editIndex);
                        //刷新父页面
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.message);
                }
            });
            return false;
        });

    });
</script>
</body>
</html>
